
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" id="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1, initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="format-detection" content="telephone=yes" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta charset="utf-8">
    <title>{{config("site.title")}}</title>
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <div id="wx_logo" style="display: none">
        <img src="{{asset('image/weixin.jpg')}}">
    </div>
</head>

<body style="background: #ebebeb;">
<header>
    <span class="app_Larrow"><a href="{{url('appdetail')}}"><img src="image/app_jiantou.png"/></a></span>
    <ul class="app_name">
        <li name="round" tip="1" class="app_active"><a href="javascript:void(0);">入围作品</a></li>
        <li name="round" tip="2"><a href="javascript:void(0);">人气作品</a></li>
    </ul>
</header>
<ul class="nav_scroll">
    {{--<li name="month"  tip="2016-06" class="activemonth"><a href="javascript:void(0);">6月</a></li>--}}
    <li name="month"  tip="2016-07" class="activemonth"><a href="javascript:void(0);">7月</a></li>
    <li name="month"  tip="2016-08"><a href="javascript:void(0);">8月</a></li>
    <li name="month"  tip="2016-09"><a href="javascript:void(0);">9月</a></li>
    <!--<li><a href="#">10月入围作品</a></li>-->
</ul>
<ul class="app_con">
    @foreach($work as $item)
        <li>
            <a href="javascript:void(0);">
                <div class="app_con_img">
                    <img src="{{asset('upload/' . $item->dir . '/' .$item->sub_dir . '/' . $item->picname)}}" />
                </div>
                <p><span>{{$item->name}}</span><span>作者：{{$item->author}}</span><span>票数：{{$item->vote}}</span></p>
                <dl name="vote" tip="{{$item->id}}">
                    <dt><img src="image/app_xin.png"/></dt>
                    <dd>投票</dd>
                </dl>
            </a>
        </li>
    @endforeach
</ul>
<p class="more"><a href="javascript:void(0);">加载更多</a></p>
</body>
<script src="{{url('/js/jquery-1.9.1.js')}}" type="text/javascript" language="JavaScript"></script>
<script src="{{url('/js/common.js')}}" type="text/javascript" language="javascript"></script>
<script type="text/javascript" language="javascript">
    $(function(){

        if($("ul.app_con li").length == 0){
            $(".more a").html("没有数据");
        }
        //点击查询
        $("li[name=round], li[name=month]").on("click", function(){
            var url = 'appindex/?';
            var name = $(this).attr("name");
            var tip = $(this).attr("tip");
            var data;
            if('round' == name){
                url += 'round=' + tip;
                tip = $("li[name=month]").attr('tip');
                url += '&month=' + tip;
                $("li[name=round]").removeClass('app_active');
                $(this).addClass("app_active");
            }else{
                url += 'month=' + tip;
                tip = $("li[name=round]").attr('tip');
                url += '&round=' + tip;
                $("li[name=month]").removeClass('activemonth');
                $(this).addClass("activemonth");
            }
            currentPage = 1;
            queryWork(url, "check");
        });

        //点击加载更多
        $(".more").on("click", function(){
            currentPage = currentPage + 1;
            var url = 'appindex/?';
            url += "month=" + $("li[name=month][class=activemonth]").attr('tip');
            url += "&round=" + $("li[name=round][class=app_active]").attr('tip');
            queryWork(url, "addmore");
        });

        var currentPage = 1;
        function queryWork(url, type) {
            url += "&page=" + currentPage;
            $.ajax({
                url:url,
                type:"GET",
                async:true,
            }).done(function(data){
                currentPage = data.current_page;
                var html = [];
                if(data.data.length>0){
                    var i=0;
                    data = data.data;
                    while(data[i]){
                        html.push('<li>');
                        html.push('<a href="javascript:void(0);">');
                        html.push('<div class="app_con_img">');
                        html.push('<img src="'+ window.location.origin + '/upload/' + data[i].dir + '/' + data[i].sub_dir + '/' + data[i].picname +'">');
                        html.push('</div>');
                        html.push('<p><span>'+ data[i].name +'</span><span>作者：'+ data[i].author +'</span><span>票数：'+ data[i].vote +'</span></p>');
                        html.push('<dl name="vote" tip="'+ data[i].id +'">');
                        html.push('<dt><img src="image/app_xin.png"></dt>');
                        html.push('<dd>投票</dd>');
                        html.push('</dl>');
                        html.push('</a>');
                        html.push('</li>');
                        i++;
                    }
                    if("addmore" == type){
                        $(".app_con").append(html.join(''));
                    }else{
                        $(".app_con").html(html.join(''));
                    }
                    $(".more a").html("加载更多");
                }else{
                    var title = ( ($(".app_active").attr("tip") == "1") ? "入围作品" : "人气作品" ) + "还在来的路上！";
                    $(".more a").html( title );
                    if(data.current_page == 1){
                        $(".app_con").html("");
                    }
                }
            });
        }


        //投票
        $(".app_con").on("click","dl[name=vote]", function(){
            var postData = {
              ip:$.getIPAddress(),
              id:$(this).attr('tip'),
              _token:"{{ csrf_token() }}"
            };
            $.ajax({
                url:"{{url('/vote')}}",
                type:"POST",
                data:postData,
                async:true,
            }).done(function(data){
                $.alert(data.message);
            }).fail(function(){

            });
        });


    })
</script>
</html>